import {layer,template,message} from 'nuijs'
import tree from '{pub}/component/tree';
import JSON from 'JSON';

import store from 'store';
import {formlayer} from '{pub}/logic/tpl';
import labeltree from './labeltree';

let showlayer = function(res){
    layer({
        scrollbar:true,
        width:700,
        template:template.render.call(formlayer,formlayer.main),
        data:{
            type:'ui-form2',
            url:'application/updateApp.do',
            tpl:[{
                type:'hidden',
                name:'appId',
                field:'interplatformApplication.id'
            },{
                type:'hidden',
                name:'appKey',
                field:'interplatformApplication.appKey'
            },{
                type:'text',
                label:'应用名称',
                field:'interplatformApplication.appName',
                xing:'fff'
            },{
                type:'select2',
                label:'应用标签',
            },{
                type:'tree',
                label:'能力获取'
            },{
                type:'number',
                label:'流量调整',
                name:'nDaycount',
                field:'interplatformApplication.nDaycount',
                rule:"{required:true}",
                message:"{required:'流量调整不能为空'}"
            },{
                type:'textarea',
                label:'调整意见',
                name:'idea',
                // rule:"{required:true,RegExp:/^.{10,50}/g}",
                // message:"{required:'申请意见不能为空',RegExp:'请输入10~50个字符'}"
                rule:"{required:true}",
                message:"{required:'申请意见不能为空'}"
            }],
            data:res,
        },
        button:[{
            id:'confirm',
            text:'确定',            
            callback(self){
                self.main.find('form').submit();
                return false;
            }
        }],
        onInit(self){
            labeltree.call(self,res);
            self.resize();
            // self.main.find('textarea').tree({
            //     data:'nihao'
            // });
        }
    })
}
export function adjustlayer(e,elem,data){
    this.self.request('post','application/appAdjustment.do',elem.closest('tr').data(),function(res){
        let appType = res.interplatformApplication.appType
        store('appTypetmp',[{id:appType,name:store('appType')[appType]}]);
        showlayer(res);
    })
}